<?php
namespace Backend\Models\RedPackets;

use Backend\Models\Base;

class Log extends Base
{
    public function initialize()
    {
        parent::initialize();
    }

    public function getSource()
    {
        return 'daishu_red_packet_log';
    }

    public function gets($limit, $offset)
    {
        $query = $this->select('*')->from(self::class)->limit($limit, $offset);
        try {
            $result = $query->getQuery()->execute()->toArray();
            if ($result !== false && is_array($result)) {
                return $result;
            }
        } catch (\Exception $ex) {
            $this->errorLog('SELECT', $query->getPhql(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }

    public function getCount()
    {
        $query = $this->select('count(*) AS cnt')->from(self::class);
        try {
            $result = $query->getQuery()->execute()->toArray();
            if ($result !== false && is_array($result) && count($result) > 0) {
                return $result[0]['cnt'];
            }
        } catch (\Exception $ex) {
            $this->errorLog('SELECT', $query->getPhql(), $ex->getMessage(), __FILE__, __LINE__);
        }
        return false;
    }
}
